package cn.imnaer.service.rest.resquest.model;

import cn.imnaer.common.factory.JacksonUtil;
import cn.imnaer.service.persistence.model.User;

public class UserRegisterParams {
    private String emailOrMobile;
    private String password;
    private String gender;
    private String birthday;
    private String name;

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

  

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public static UserRegisterParams parseToModel(String json) {

        return (UserRegisterParams) JacksonUtil.jsonToBean(json, UserRegisterParams.class);


    }

    public String getEmailOrMobile() {
        return emailOrMobile;
    }

    public void setEmailOrMobile(String emailOrMobile) {
        this.emailOrMobile = emailOrMobile;
    }

    public User transformUser() {
        User user = new User();
        user.setPassword(this.password);
        if (this.emailOrMobile.contains("@")) {
            user.setEmail(this.emailOrMobile);
        } else if (this.emailOrMobile.length() == 11) {
            user.setMobile(this.emailOrMobile);
        }
        user.setGender(this.gender);
        user.setName(this.name);
        user.setBirthday(this.birthday);
        return user;
    }


}
